#pragma once
//封装锁
#include<iostream>
#include<pthread.h>
using namespace std;

class Mutex
{   
public:
    Mutex(pthread_mutex_t *mtx):pmtx(mtx)
    {
    }

    void lock()
    {
        cout<<"要进行加锁"<<endl;
        pthread_mutex_lock(pmtx);
    }

    void unlock()
    {
        cout<<"我要解锁"<<endl;
        pthread_mutex_unlock(pmtx);
    }
    ~Mutex()
    {}

private:
    pthread_mutex_t *pmtx;
};

//智能指针（Rull）方案
class lockGuard
{
public:
    lockGuard(pthread_mutex_t * mtx):mtx_(mtx)
    {
        mtx_.lock();
    }

    ~lockGuard()
    {
        mtx_.unlock();
    }
private:
    Mutex mtx_;
};